﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AcademicPlanner.Domain
{
	/// <summary>
	/// DomainException is the base class for all application level exceptions
	/// in the domain layer of the AcademicPlanner application.
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
    abstract public class DomainException : ApplicationException
    {
		/// <summary>
		/// The error code associated with this DomainException.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		protected DomainErrorCode errorCode;


		/// <summary>
		/// Gets the error code associated with this DomainException.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public DomainErrorCode ErrorCode { get { return errorCode; } }

		/// <summary>
		/// Gets the error message associated with this DomainException based on its error code.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public override string Message { get { return GetErrorCodeMessage(errorCode); } }


		/// <summary>
		/// Constructs a DomainException by initializing its <c>errorCode</c> with the given
		/// <c>DomainErrorCode</c>.
		/// </summary>
		/// <param name="pCode">The <c>DomainErrorCode</c> for this DomainException.</param>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public DomainException(DomainErrorCode pCode) : base()
		{
			errorCode = pCode;
		}

		/// <summary>
		/// Constructs a DomainException by initializing its <c>errorCode</c> with the given
		/// <c>DomainErrorCode</c> and its <c>InnerException</c> with the given <c>Exception</c>.
		/// </summary>
		/// <param name="pCode">The <c>DomainErrorCode</c> for this DomainException.</param>
		/// <param name="pInnerException">The <c>InnerException</c> for this DomainException.</param>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public DomainException(DomainErrorCode pCode, Exception pInnerException)
			: base("", pInnerException)
		{
			errorCode = pCode;
		}


		/// <summary>
		/// Gets the error message associated with a given <c>DomainErrorCode</c>.
		/// </summary>
		/// <param name="pCode">The <c>DomainErrorCode</c> to get the associated message with.</param>
		/// <returns>The error message associated with the given <c>DomainErrorCode</c>.</returns>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public static string GetErrorCodeMessage(DomainErrorCode pCode)
		{
			// TODO: RETURN MORE COMPREHENSIBLE MESSAGE
			return pCode.ToString();
		}
    }
}
